package com.carbon.chainmaker;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;


/**
 * @author : Li Jun
 * @since : 2021-06-12 08:52
 **/
@SpringBootApplication(scanBasePackages = "com.carbon",exclude ={ SecurityAutoConfiguration.class} )
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.carbon")
@MapperScan({"com.carbon.*.mapper"})
public class ChainMakerApplication implements CommandLineRunner {
    // 注入主数据源名称（检查是否读到 primary 配置）
    @Value("${spring.datasource.dynamic.primary:未读取到}")
    private String dynamicPrimary;

    // 注入主数据源 URL（检查是否读到 carbonDb 的配置）
    @Value("${spring.datasource.dynamic.datasource.carbonDb.url:未读取到}")
    private String carbonDbUrl;

    // 注入 RocketMQ 地址（检查是否读到 RocketMQ 配置）
    @Value("${rocketmq.name-server:未读取到}")
    private String rocketMqNameServer;

    // 项目启动后执行，打印配置信息
    @Override
    public void run(String... args) throws Exception {
        System.out.println("=== 配置读取验证 ===");
        System.out.println("主数据源名称：" + dynamicPrimary);
        System.out.println("carbonDb URL：" + carbonDbUrl);
        System.out.println("RocketMQ name-server：" + rocketMqNameServer);
        System.out.println("===================");
    }

    /**
     * 启动方法
     */
    public static void main(String[] args) {
        SpringApplication.run(ChainMakerApplication.class,args);
    }
}
